#include "board.h"
#include "rtthread.h"

static void led1_thread_entry(void* parameter);
static void lcd_thread_entry(void* parameter);
static void key_thread_entry(void* parameter);

static rt_thread_t led1_thread = RT_NULL;
static rt_thread_t lcd_thread = RT_NULL;
static rt_thread_t key_thread = RT_NULL;

int main(void)
{	
		ILI9341_GramScan ( 6 );//设置显示模式
	
	
    led1_thread = 
			rt_thread_create("led1",led1_thread_entry,RT_NULL,512,3,20);
	  rt_thread_startup(led1_thread);
	
		lcd_thread = 
				rt_thread_create("lcd",lcd_thread_entry,RT_NULL,512,3,20);
		rt_thread_startup(lcd_thread);
	
		key_thread = 
				rt_thread_create("key",key_thread_entry,RT_NULL,512,2,20);
		rt_thread_startup(key_thread);	
}

static void led1_thread_entry(void* parameter)
{
	int color = 0;
	while(1)
	{
		LED_Color(color%7);
		color++;
		rt_thread_delay(1000);
		
	}
}
static void lcd_thread_entry(void* parameter)
{
	int num = 0;
	char disp[10];
	while(1)
	{
		sprintf(disp,"Num:%d",num++);
		ILI9341_DispStringLine_EN(LINE(1),disp);
		rt_thread_delay(1000);
	}

}

static void key_thread_entry(void* parameter)
{
	rt_err_t uwRet = RT_EOK;
	while(1)
	{
		if(GET_KEY1)
		{
			uwRet = rt_thread_suspend(led1_thread);
			rt_kprintf("led1_thread suspend\n");
			if(RT_EOK == uwRet){
				rt_kprintf("Success Suspend\n");
			}
			else{
				rt_kprintf("Fail Suspend:%lx\n",uwRet);
			}
		}
		if(GET_KEY2)
		{
			uwRet = rt_thread_resume(led1_thread);
			rt_kprintf("led1_thread resume\n");
			if(RT_EOK == uwRet){
				rt_kprintf("Success Resume\n");
			}
			else{
				rt_kprintf("Fail Resume:%lx\n",uwRet);
			}
		}
		rt_thread_delay(20);
	}
}
